import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
import { ActionSheet, Toast } from 'antd-mobile'
import wechat from '@/assets/images/share_wechat.png'
import pyq from '@/assets/images/share_discover.png'
import sina from '@/assets/images/share_sina.png'
import qq from '@/assets/images/share_qq.png'
import qzone from '@/assets/images/share_qzone.png'
export default class ShareSheet extends PureComponent {
    static propTypes = {
        url: PropTypes.string,
        title: PropTypes.string,
        pic: PropTypes.string
    }
    
    dataList = [
        {
            title: '微信',
            icon: wechat,
            share: false
        },
        {
            title: '朋友圈',
            icon: pyq,
            share: false
        },
        {
            title: '微博',
            icon: sina,
            share: true
        },
        {
            title: 'QQ',
            icon: qq,
            share: true
        },
        {
            title: 'QQ空间',
            icon: qzone,
            share: true
        }
    ].map(item => ({
        ...item,
        icon: <img src={item.icon} alt={item.title} style={{width: 36}} />        
    }))
    

    show = () => {
        ActionSheet.showShareActionSheetWithOptions({
            options: this.dataList,
            // title: '分享至',
            message: '立即分享给好友',
        },
        (buttonIndex) => {
            const btn = this.dataList[buttonIndex]
            if (!btn) {
                return
            }
            if (!btn.share) {
                Toast.info('请使用微信打开，并点击右上角分享功能分享给好友', 3)
            } else {
                let req = ''
                const { url, title, pic } = this.props
                const encodeUrl = encodeURIComponent(url)
                if (btn.title === '微博') {
                    req = `http://service.weibo.com/share/share.php?url=${encodeUrl}&sharesource=weibo&title=${title}&pic=${pic}&appkey=`
                } else if (btn.title === 'QQ') {
                    req = `http://connect.qq.com/widget/shareqq/index.html?url=${encodeUrl}&sharesource=qzone&title=${title}&pics=${pic}&summary=${title}&desc=${title}`
                } else if (btn.title === 'QQ空间') {
                    req = `http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=${encodeUrl}&title=${title}&desc=${title}&summary=${title}&pics=${pic}`
                }
                req && window.open(req)
            }
        });
    }

    render() {
        return (
            <>                
            </>
        )
    }
}
